/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sockets.exemplos2;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 *
 * @author andersonribeiro
 */
public class Servidor {

    private static int porta = 12345;

    public int getPorta() {
        return porta;
    }

    public void setPorta(int porta) {
        Servidor.porta = porta;
    }

    public static void main(String[] args) throws IOException {

        ServerSocket servidor = new ServerSocket(porta);

        Servidor s = new Servidor();
        System.out.println("Porta " + s.getPorta() + " aberta");

        Socket cliente = servidor.accept();
        System.out.println("Nova conexão com o cliente " + cliente.getInetAddress().getHostAddress());

        Scanner scanner = new Scanner(cliente.getInputStream());

        while (scanner.hasNextLine()) {
            System.out.println(scanner.nextLine());
            /*if (scanner.toString().trim().equals("fim")) {
                System.exit(0);
            }*/
        }

        scanner.close();
        servidor.close();
        cliente.close();

    }
}
